
using System;
using System.Collections;
using QdbUnit;
using Qdb.Tests.Common.Freespace;
using Qdb.Tests.Common.Handlers;
using Qdb.Tests.Common.Migration;
using Qdb.Tests.Util;
using Sharpen;

namespace Qdb.Tests.Common.Migration
{
	public class QdbMigrationTestSuite : ITestSuiteBuilder
	{
		public static void Main(string[] args)
		{
			new ConsoleTestRunner(typeof(QdbMigrationTestSuite)).Run();
		}

		public virtual IEnumerator GetEnumerator()
		{
			return new QdbMigrationSuiteBuilder(TestCases(), Libraries()).GetEnumerator();
		}

		protected virtual string[] Libraries()
		{
			if (true)
			{
				return QdbMigrationSuiteBuilder.All;
			}
			if (true)
			{
				// run against specific libraries + the current one
				string javaPath = "qdb.archives/java1.2/qdb-5.7-java1.2.jar";
				string netPath = "qdb.archives/net-2.0/7.4/Qdb.dll";
				return new string[] { WorkspaceServices.WorkspacePath(javaPath) };
			}
			return QdbMigrationSuiteBuilder.Current;
		}

		protected virtual Type[] TestCases()
		{
			Type[] classes = new Type[] { typeof(BooleanHandlerUpdateTestCase), typeof(ByteHandlerUpdateTestCase
				), typeof(CascadedDeleteFileFormatUpdateTestCase), typeof(CharHandlerUpdateTestCase
				), typeof(DateHandlerUpdateTestCase), typeof(DeletionUponFormatMigrationTestCase
				), typeof(DoubleHandlerUpdateTestCase), typeof(EncryptedFileMigrationTestCase), 
				typeof(FloatHandlerUpdateTestCase), typeof(IntHandlerUpdateTestCase), typeof(InterfaceHandlerUpdateTestCase
				), typeof(LongHandlerUpdateTestCase), typeof(MultiDimensionalArrayHandlerUpdateTestCase
				), typeof(NestedArrayUpdateTestCase), typeof(ObjectArrayUpdateTestCase), typeof(
				PlainObjectUpdateTestCase), typeof(QueryingMigrationTestCase), typeof(ShortHandlerUpdateTestCase
				), typeof(StringHandlerUpdateTestCase), typeof(IxFreespaceMigrationTestCase), typeof(
				FreespaceManagerMigrationTestCase) };
			// Order to run freespace/Encrypted tests last is
			// deliberate. Global configuration Qdb.configure()
			// is changed in the #setUp call and reused.
			return AddJavaTestCases(classes);
		}

		protected virtual Type[] AddJavaTestCases(Type[] classes)
		{
			Type[] javaTestCases = null;
			if (javaTestCases == null)
			{
				return classes;
			}
			int len = javaTestCases.Length;
			Type[] allClasses = new Type[classes.Length + len];
			System.Array.Copy(javaTestCases, 0, allClasses, 0, len);
			System.Array.Copy(classes, 0, allClasses, len, classes.Length);
			return allClasses;
		}
	}
}
